var _Step = require('scenes/game/toturial/step.js');
var _inherit = require('core/inherit.js');
var _global = require('global/global.js');

function Step() {
    _Step.call(this);
    this.mFinish = false;
    this.mMoveCount = 0;
}
_inherit(Step, _Step);
Step.prototype.onMergeFinish = function () {
    this.mMoveCount++;
    if (this.mMoveCount == 5) {
        this.mMoveCount = 0;
        this.mPool.addSlots([3], true);
    }
};
Step.prototype.onMergeFind = function (index, count) {
    if (count >= 24) {
        this.mFinish = true;
    }
};
Step.prototype.onAbsorbStart = function (accept) {
    if (accept) {
        var merged = this.mCells.getMergeHis().getCurrent();
        if (merged.getMergeCount() > 0) {
            this.mCells.checkMerge(this.mGameArea.getPredict(), this);

            if (this.mFinish) {
                this.mToturial.nextStep();

                this.mToturial = null;
                this.mGameArea = null;
                this.mPool = null;
                this.mCells = null;
            }
        }
    }
};
Step.prototype.onStart = function (toturial, local) {
    this.mToturial = toturial;
    this.mLocal = local;

    this.mToturial.showHeaderTip(this.createHeader('Make a 24!'));

    this.mCells = this.mLocal.find('gamearea.cells');
    this.mGameArea = this.mLocal.find('gamearea');
    this.mPool = this.mLocal.find('gamearea.slotpool');

    //var numbers = this.mCells.getCellsCount();
    this.mPool.addSlots([1, 2, 3], true);
};

module.exports = Step;